@extends('layouts.admin')
@push('morecss')
    <link href="{{ mix('css/admin/material_news.css') }}" rel="stylesheet">
    <link href="//cdn.tudouyu.cn/AdminInspinia/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css"
          rel="stylesheet">
    <!--webuploader上传组件CSS-->
    <link rel="stylesheet" type="text/css" href="/vendor/webuploader/webuploader.css">
@endpush

@push('morescript')
    <!--webuploader上传组件JS-->
    <script type="text/javascript" src="/vendor/webuploader/webuploader.js"></script>
    <!--瀑布流-->
    <script src="//cdn.tudouyu.cn/masonry-layout/dist/masonry.pkgd.min.js"></script>
    <script src="//cdn.tudouyu.cn/imagesloaded/imagesloaded.pkgd.min.js"></script>
    <script type="application/javascript">
        let page_params = {
            @can('admin.wxmaterialvideo.index')
            url_list: '{{ route('admin.wxmaterialvideo.index') }}',
            @endcan
            @can('admin.wxmaterialvideo.create')
            url_add: '{{ route('admin.wxmaterialvideo.create') }}',
            @endcan
            @can('admin.wxmaterialvideo.update')
            url_edit: '{{ route('admin.wxmaterialvideo.update') }}',
            @endcan
            @can('admin.wxmaterialvideo.destroy')
            url_del: '{{ route('admin.wxmaterialvideo.destroy') }}',
            @endcan
            @can('admin.wxmaterialvideo.upwx')
            url_upwx: '{{ route('admin.wxmaterialvideo.upwx') }}',
            @endcan
            @can('admin.wxmaterialvideo.sync')
            url_sync: '{{ route('admin.wxmaterialvideo.sync') }}',
            @endcan
            catList:@json($catList)
        }
    </script>
    <!-- require page js -->
    <script src="{{ mix('js/admin/wxmaterialvideo_index.js') }}"></script>
@endpush
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight ecommerce" id="ibox-content">
        <div class="ibox-content m-b-sm border-bottom">
            <div class="row">
                <div class="col-sm-4">
                    @can('admin.wxmaterialvideo.create')
                        <button class="btn btn-primary" v-on:click="add()"><i class="fa fa-plus"></i> 上传视频</button>
                    @endcan
                    @can('admin.wxmaterialvideo.sync')
                        <button class="btn btn-primary" v-on:click="sync" type="button" id="btn-sync"><i class="fa fa-cloud-download"></i>
                            拉取微信端视频
                        </button>
                    @endcan
                </div>
            </div>
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            <div class="row">
                <div class="col-sm-12">
                    由于视频上传比较耗时，而且会会有些格式无法上传，此处建议先在微信服务号的mp后台上传，然后再同步拉取下来使用。
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="row">
                <div class="col-sm-4">
                    <div class="form-group">
                        <label class="control-label" for="keyword">关键字</label>
                        <input type="text" id="keyword" name="keyword" v-model="searchParams.keyword" placeholder="请输入搜索关键字"
                               class="form-control">
                    </div>
                </div>
                <div class="col-sm-4">
                    <div class="form-group">
                        <label class="control-label" for="product_name">分类</label>
                        <treeselect v-model="searchParams.catId" :options="cat_list" :normalizer="catNormalizer" placeholder="选择素材分类..." />
                    </div>
                </div>
                <div class="col-sm-2">
                    <div class="form-group">
                        <label class="control-label" for="product_name">&nbsp;&nbsp;</label>
                        <div>
                            <button class="btn btn-primary" type="button" id="btn-search" v-on:click="search"><i class="fa fa-search"></i>
                                搜索
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            <div class="row grid" v-masonry transition-duration="0.3s" item-selector=".grid-item">
                <div class="col-md-4 grid-item" v-for="(item, index) in material_list" v-masonry-tile>
                    <material-preview v-bind:material-data="item" :is-edit="true">
                        <div class="m-t text-right">
                            <button v-on:click="upwx(item.material_id)" v-show="page_params.url_upwx" class="btn btn-default btn-sm">
                                <i class="fa fa-cloud-upload"></i>
                                上传
                            </button>
                            <button v-on:click="edit(index)" v-show="page_params.url_edit" class="btn btn-default btn-sm">
                                <i class="fa fa-pencil"></i>
                                编辑
                            </button>
                            <button v-on:click="del(item.material_id)" v-show="page_params.url_del" class="btn btn-default btn-sm">
                                <i class="fa fa-trash"></i>
                                删除
                            </button>
                        </div>
                    </material-preview>
                </div>

            </div>
            <div class="row text-center">
                <pagination :pagination="pagination" :callback="query" :options="paginationOptions"></pagination>
            </div>
        </div>
    </div>

    <!--图片上传层-->
    <div id="box-form" style="display: none;">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form method="POST" class="form-horizontal">
                        <input type="hidden" name="material_id" id="material_id" v-model="materialCurData.material_id" value="">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">素材分类</label>
                            <div class="col-sm-4">
                                <treeselect v-model="materialCurData.cat_id" :options="cat_list" :normalizer="catNormalizer" placeholder="选择素材分类..." />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">名称</label>
                            <div class="col-sm-10">
                                <input type="text" name="title" id="title" v-model="materialCurData.title" class="form-control">
                                <span class="help-block m-b-none">定义改素材名称</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">描述</label>
                            <div class="col-sm-10">
                                <textarea name="description" id="description" v-model="materialCurData.description" class="form-control"></textarea>
                                <span class="help-block m-b-none">
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">视频文件</label>
                            <div class="col-sm-10">
                                <input id="view_url" name="view_url" type="text" readonly v-model="materialCurData.view_url" class="form-control">
                                <div v-show="!materialCurData.material_id" id="btn-upload">选择视频</div>
                                <p v-show="!materialCurData.material_id" class="help-block">MP4格式,文件大小不超过10M</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="is_forever">素材类型：</label>
                            <div class="input-group">
                                <div class="radio radio-primary radio-inline">
                                    <input type="radio" id="is_forever_1" value="1" name="is_forever" checked v-model="materialCurData.is_forever">
                                    <label for="is_forever_1"> 永久素材 </label>
                                </div>
                                <div class="radio radio-primary radio-inline">
                                    <input type="radio" id="is_forever_2" value="0" name="is_forever" v-model="materialCurData.is_forever">
                                    <label for="is_forever_2">
                                        临时素材 </label>
                                </div>
                                <span class="help-block m-b-none">用于群发的图文其素材类型必须是永久素材</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-4">
                                <button class="btn btn-primary" v-on:click="materialSave" type="button" id="btn-sub">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection